$(document).ready(function(){
	changeDate();
	jumpPageWait(1);
});

function changeDate() {
	var partern = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
	
	if (!partern.test($("#datePicker").val())) {return;}
	selectedDate = $("#datePicker").val();
	
	jumpPage_top(1);
}

function jumpPage_top(targetPage) {
	var requestUrl = "get_maintain_cars";
	var params = {
		start_date:selectedDate,
		end_date:selectedDate,
		page:targetPage,
		pageSize:5,
		status:9
	};
	
	$.post(requestUrl, params, function(ret){
		$("#div_today_maintain").html("");
		var newHtml = "";
		var item;
		for (var i = 0; ret.resultData.items && i < ret.resultData.items.length; i++) {
			item = ret.resultData.items[i];
			newHtml += '<div class="order_item" style="margin-top: 2px" onmouseover="selectMaintainItem(this);" onclick="showMaintainOrderDetail(\'' + item.orderId + '\', \'maintain_customer\');">';
			newHtml += '	<div class="col_name">' + item.name + '</div>';
			newHtml += '	<div class="col_license">' + item.carLicense + '</div>';
			newHtml += '	<div class="col_model">' + item.carModel + '</div>';
			newHtml += '	<div class="col_mobile">' + item.mobile + '</div>';
			newHtml += '	<div style="clear: both;"></div>';
			newHtml += '</div>';
		}
		
		//显示分页信息
		if (ret.resultData.total_num && ret.resultData.total_num > 5) {
			pages = Math.ceil(ret.resultData.total_num/5);
			var page = new Page(pages);
			page.currentPage = targetPage;
			newHtml += page.genPageHtml("jumpPage_top");
		}
		
		$("#div_today_maintain").html(newHtml);
		$("#maintain_statics").html($("#datePicker").val() + "总计养护车辆" + ret.resultData.total_num + "辆");
		topHtml = $("#div_top_tabhost").html();
	}, dataType="json");
}

function jumpPageWait(targetPage) {
	var requestUrl = "get_maintain_cars";
	var params = {
		page:targetPage,
		pageSize:5,
		status:0
	};
	
	$.post(requestUrl, params, function(ret){
		$("#div_wait_maintain").html("");
		var newHtml = "";
		var item;
		for (var i = 0; ret.resultData.items && i < ret.resultData.items.length; i++) {
			item = ret.resultData.items[i];
			newHtml += '<div class="order_item" style="margin-top: 2px" onmouseover="selectMaintainItem(this);" onclick="showMaintainOrderDetail(\'' + item.orderId + '\', \'maintain_customer\');">';
			newHtml += '	<div class="col_name">' + item.name + '</div>';
			newHtml += '	<div class="col_license">' + item.carLicense + '</div>';
			newHtml += '	<div class="col_model">' + item.carModel + '</div>';
			newHtml += '	<div class="col_mobile">' + item.mobile + '</div>';
			newHtml += '	<div style="clear: both;"></div>';
			newHtml += '</div>';
		}
		
		//显示分页信息
		if (ret.resultData.total_num && ret.resultData.total_num > 5) {
			pages = Math.ceil(ret.resultData.total_num/5);
			var page = new Page(pages);
			page.currentPage = targetPage;
			newHtml += page.genPageHtml("jumpPageWait");
		}
		
		$("#div_wait_maintain").html(newHtml);
		$("#wait_statics").html("排队等待中" + ret.resultData.total_num + "辆");
		topHtml = $("#div_top_tabhost").html();
	}, dataType="json");
}